<?php
namespace app\admin\validate;

use think\Validate;

class MarketValidate extends Validate
{
    protected $rule = [
        'code' => 'require|unique:Market|checkCode',
        "id" => 'require',
        "icon" => 'require',
        "sort"=>'require|number',
        "status" => 'require|in:1,-1',
        "is_primary"=>'in:0,1'
    ];

    protected $message = [
        'code.require' => '币种代码必须填写',
        'code.checkCode' => '币种代码不需要usdt',
        "id.require" => "缺少id",
        "sort.require"=>"排序必须填写",
        "sort.number"=>"排序必须是数字",
        "status.in" => "状态值错误",
        "status.require" => "缺少状态值",
        "is_primary.in"=>"是否放在首页值错误"
    ];

    protected $scene = [
        'add' => ['code','sort','icon'],
        'edit' => ['code','id','sort','icon'],
        'status'=>['id','status'],
    ];

    protected function checkCode($value)
    {
        if (str_contains(strtolower($value),'usdt')) {
            return false;
        }
        return true;
    }
}